cmake_minimum_required(VERSION 3.20)
#配置vcpkg
#set(CMAKE_TOOLCHAIN_FILE "D:/Apps/vcpkg/scripts/buildsystems/vcpkg.cmake")
project(PinTu)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


if (MSVC)
    add_compile_options(/utf-8)
    find_package(SDL3 CONFIG REQUIRED PATHS "F:/libs/SDL3-devel-3.2.0-VC/SDL3-3.2.0")
    find_package(SDL3_image CONFIG REQUIRED PATHS "F:/libs/SDL3_image-devel-3.2.0-VC/SDL3_image-3.2.0")
endif ()
#mingw查找库
if (MINGW)
    find_package(SDL3 CONFIG REQUIRED PATHS "F:/libs/SDL3-3.2.0")
    find_package(SDL3_image CONFIG REQUIRED PATHS "F:/libs/SDL3_image-3.2.0")
endif ()
file(GLOB_RECURSE RESOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/resources/*")

add_executable(${PROJECT_NAME} src/main.cpp)
#复制DLL
if (WIN32)
    add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy
            $<TARGET_FILE:SDL3_image::SDL3_image>
            $<TARGET_FILE_DIR:${PROJECT_NAME}>
            COMMENT "COPY SDL3_image DLL"
    )
    add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy
            $<TARGET_FILE:SDL3::SDL3>
            $<TARGET_FILE_DIR:${PROJECT_NAME}>
            COMMENT "COPY SDL3 DLL"
    )
endif ()

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E make_directory
        "$<TARGET_FILE_DIR:${PROJECT_NAME}>/resources"
        COMMAND ${CMAKE_COMMAND} -E copy_directory
        "${CMAKE_SOURCE_DIR}/resources"
        "$<TARGET_FILE_DIR:${PROJECT_NAME}>/resources"
        COMMENT "Copying resource files to executable directory..."
)
target_link_libraries(${PROJECT_NAME} PRIVATE SDL3::SDL3 SDL3_image::SDL3_image)
if (MSVC)
    add_compile_options("/utf-8")
    set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
endif ()
if (MINGW)
    target_link_options(${PROJECT_NAME} PRIVATE -mwindows)
endif ()